﻿/* $RCSFile: ADNDynBusinessUnit.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/CRMWrapper3/DynEntities/ADNDynBusinessUnit.cs $
 * $log$
 * Revision 19 2010/10/02 14:01:48  christian.surieux
 *   Corrected a bug in allmost everyADNDyn file for PrimaryFieldVualue
 * Revision 6 2010/08/06 19:56:32  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using CrmSdk;

namespace AddonNice.CRMWrapper
{
    public class ADNDynBusinessUnit: DynEntity
    {
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.businessunit)
            {}

            public override Type DynType
            { get { return typeof(ADNDynBusinessUnit); } }

            public override string DynTypename
            {   get{ return CrmStr.businessunit;}}

            public override DynEntity Build()
            {   return new ADNDynBusinessUnit();}

            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   return new ADNDynBusinessUnit(w, dEntity, wproperties, null);}

            public override DynEntity Build(CRMWrapperBase w, string PrimaryFieldValue)
            {   return new ADNDynBusinessUnit(w,PrimaryFieldValue);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynBusinessUnit(w,PrimaryKeyValue);}
        }

        static ADNDynBusinessUnit(){new Ftor();} 

        public override bool HasOwnerProperty
        {
            get{   return false;}
        }

        public override bool HasBusinessUnitProperty
        {
            get{   return false;}
        }

        /// <summary>
		/// Reserved for template methods: do not use directly
		/// </summary>
        public ADNDynBusinessUnit(): base()
		{}

        /// <summary>
        /// Ctor for querying crm to find corresponding account/contact
        /// </summary>
        public ADNDynBusinessUnit(CRMWrapperBase w,Guid CrmId)
            : base(w,CrmStr.businessunit, CrmId)
        {}

        public ADNDynBusinessUnit(CRMWrapperBase w,string PrimaryFiedlValue)
            : base(w,CrmStr.businessunit)
        {
            name    =   PrimaryFiedlValue;
        }

        public ADNDynBusinessUnit(CRMWrapperBase w, InternalDynamicEntity dEntity)
            : base(w,CrmStr.businessunit,dEntity,null,null)
        {}

        public ADNDynBusinessUnit(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection prop, InternalColumnSet s)
            : base(w,CrmStr.businessunit,dEntity, prop, s)
        {}

        /// <summary>
        /// Ctor for querying crm to find corresponding account/contact
        /// </summary>
        public ADNDynBusinessUnit(ResetWrapperHandler fn,Guid CrmId)
            : base(fn,CrmStr.businessunit, CrmId)
        {}

        public ADNDynBusinessUnit(ResetWrapperHandler fn,string PrimaryFiedlValue)
            : base(fn,CrmStr.businessunit)
        {
            name    =   PrimaryFiedlValue;
        }

        public ADNDynBusinessUnit(ResetWrapperHandler fn, InternalDynamicEntity dEntity)
            : base(fn,CrmStr.businessunit,dEntity,null,null)
        {}

        public ADNDynBusinessUnit(ResetWrapperHandler fn, InternalDynamicEntity dEntity, PropertyDescriptorCollection prop, InternalColumnSet s)
            : base(fn,CrmStr.businessunit,dEntity, prop, s)
        {}
        
        /// <summary>
		/// Crm Key
		/// </summary>
        [CrmDynAttribute(CrmStr.businessunit)]
        public Guid businessunitid
		{
			get
			{
				return KeyPropertyValue(CrmStr.businessunitid);
			}
			set
			{
				AddKeyProperty(CrmStr.businessunitid, value);
			}
		}

        protected override void SetCrmIdProperty(Guid crmId)
        {
           if ( !dicProperty.ContainsKey(CrmStr.businessunitid) || KeyPropertyValue(CrmStr.businessunitid) != crmId )
                businessunitid   =   crmId;
        }
        
        public override string PrimaryFieldName
        {
            get
            {
               return CrmStr.name;
            }
           set
           {}
        }

        /// <summary>
        /// Value contained in the PrimaryField for the DynEntity or empty if no PrimaryField
        /// </summary>
        public override string PrimaryFieldStringValue
        {
            get
            {
                return name;
            }
            set
            {
                name =   value;
            }
        }

        public override Guid PrimaryKeyGuidValue
        {
           get
           {
                return businessunitid;
           }
           set
           {
               businessunitid    =   value;
           }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public string emailaddress
		{
			get
			{
				return StringPropertyValue(CrmStr.emailaddress);
			}
			set
			{
				AddStringProperty(CrmStr.emailaddress,value);
			}
		}


        [CrmDynAttribute(CrmStr.businessunit)]
		public string costcenter
		{
			get
			{
				return StringPropertyValue(CrmStr.costcenter);
			}
			set
			{
				AddStringProperty(CrmStr.costcenter,value);
			}
		}

       
        [CrmDynAttribute(CrmStr.businessunit)]
		public string description
		{
			get
			{
				return StringPropertyValue(CrmStr.description);
			}
			set
			{
				AddStringProperty(CrmStr.description,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
		public string disabledreason
		{
			get
			{
				return StringPropertyValue(CrmStr.disabledreason);
			}
			set
			{
				AddStringProperty(CrmStr.disabledreason,value);
			}
		}
        
        [CrmDynAttribute(CrmStr.businessunit)]
		public string divisionname
		{
			get
			{
				return StringPropertyValue(CrmStr.divisionname);
			}
			set
			{
				AddStringProperty(CrmStr.divisionname,value);
			}
		}
        
        [CrmDynAttribute(CrmStr.businessunit)]
		public string fileasname
		{
			get
			{
				return StringPropertyValue(CrmStr.fileasname);
			}
			set
			{
				AddStringProperty(CrmStr.fileasname,value);
			}
		}
         
        [CrmDynAttribute(CrmStr.businessunit)]
		public string ftpsiteurl
		{
			get
			{
				return StringPropertyValue(CrmStr.ftpsiteurl);
			}
			set
			{
				AddStringProperty(CrmStr.ftpsiteurl,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public bool isdisabled
        {
            get
            {
				return BooleanPropertyValue(CrmStr.isdisabled);
            }
            set 
             {
				AddBooleanProperty(CrmStr.isdisabled,value);
             }
        }

        /// <summary>
        /// InheritAll 1023 Sets the flags for all of the inheritance values. 
        /// InheritCompetitor  8 Business inherits competitors from parent business. 
        /// InheritEmailtemplate  2 Business inherits e-mail templates from parent business. 
        /// InheritNone  0 Does not inherit from parent business. 
        /// InheritProcesstemplate 1 Child business units must inherit process templates from this business. 
        /// InheritReferralsource  4 Child business units must inherit referral sources from this business. 
        /// InheritSalesprocess  16 Business inherits sale processes from parent business. 
        /// MustInheritCompetitor  256 Business inherits competitors from parent business. 
        /// MustInheritEmailtemplate  64 Child business units must inherit e-mail templates from this business. 
        /// MustInheritProcesstemplate  32 Business inherits process templates from parent business. 
        /// MustInheritReferralsource  128 Child business units must inherit referral sources from this business. 
        /// MustInheritSalesprocess  512 Business inherits sale processes from parent business. 
        /// </summary>
        public int inheritancemask 
        {
            get
            {
                if ( ContainsKey(CrmStr.inheritancemask) )
                    return NumberPropertyValue(CrmStr.inheritancemask);
                return 0;
            }
            set
            {
                AddNumberProperty(CrmStr.inheritancemask,value);
            }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public decimal creditlimit
        {
            get
            {
                if ( ContainsKey(CrmStr.creditlimit) )
                    return MoneyPropertyValue(CrmStr.creditlimit);
                return 0m;
            }
            set
            {
                AddMoneyProperty(CrmStr.creditlimit,value);
            }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public decimal creditlimit_base
        {
            get
            {
                if ( ContainsKey(CrmStr.creditlimit_base) )
                    return MoneyPropertyValue(CrmStr.creditlimit_base);
                return 0m;
            }
        }

        string _DefaultCalendarName   =   CrmStr.calendar;
		public string DefaultCalendarName
		{
			get
			{
				return _DefaultCalendarName;
			}
			set
			{
                switch (value)
                {
                    case CrmStr.annualfiscalcalendar:
                    case CrmStr.calendar:
                    case CrmStr.fixedmonthlyfiscalcalendar:
                    case CrmStr.monthlyfiscalcalendar:
                    case CrmStr.quarterlyfiscalcalendar:
                    case CrmStr.semiannualfiscalcalendar:
                        _DefaultCalendarName  =   value;
                        break;
                }
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public Guid calendarid
        {
            get
            {
                return LookupPropertyValue(CrmStr.calendarid);
            }
            set
            {
                AddLookupProperty(CrmStr.calendarid,DefaultCalendarName,value);
            }
        }

        public string calendarName
        {
            get
            {
                return LookupPropertyName(CrmStr.calendarid);
            }
        }
         
        [CrmDynAttribute(CrmStr.businessunit)]
        public Guid parentbusinessunitid
		{
			get
			{
				return KeyPropertyValue(CrmStr.parentbusinessunitid);
			}
			set
			{
				AddKeyProperty(CrmStr.parentbusinessunitid, value);
			}
		}

        public string parentbusinessunitName
        {
            get
            {
                return LookupPropertyName(CrmStr.parentbusinessunitid);
            }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
		public string picture
		{
			get
			{
				return StringPropertyValue(CrmStr.picture);
			}
			set
			{
				AddStringProperty(CrmStr.picture,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string stockexchange 
		{
			get
			{
				return StringPropertyValue(CrmStr.stockexchange);
			}
			set
			{
				AddStringProperty(CrmStr.stockexchange, value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string tickersymbol 
		{
			get
			{
				return StringPropertyValue(CrmStr.tickersymbol);
			}
			set
			{
				AddStringProperty(CrmStr.tickersymbol, value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string websiteurl 
		{
			get
			{
				return StringPropertyValue(CrmStr.websiteurl);
			}
			set
			{
				AddStringProperty(CrmStr.websiteurl, value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public int utcoffset
        {
            get
            {
                if ( ContainsKey(CrmStr.utcoffset) )
                    return NumberPropertyValue(CrmStr.utcoffset);
                return 0;
            }
            set
            {
                AddNumberProperty(CrmStr.utcoffset,value);
            }
        }

        #region address1

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_primarycontactname
		{
			get
			{
				return StringPropertyValue(CrmStr.address1_primarycontactname);
			}
			set
			{
				AddStringProperty(CrmStr.address1_primarycontactname,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public int address1_addresstypecode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.address1_addresstypecode);
			}
			set
			{
				AddPicklistProperty(CrmStr.address1_addresstypecode,value);
			}
		}
       
        public string address1_addresstypecodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.address1_addresstypecode) )
                    return PicklistPropertyLabelValue(CrmStr.address1_addresstypecode);
                return string.Empty;
            }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public int address1_shippingmethodcode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.address1_shippingmethodcode);
			}
			set
			{
				AddPicklistProperty(CrmStr.address1_shippingmethodcode,value);
			}
		}

        public string address1_shippingmethodcodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.address1_shippingmethodcode) )
                    return PicklistPropertyLabelValue(CrmStr.address1_shippingmethodcode);
                return string.Empty;
            }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_name
		{
			get
			{
				return StringPropertyValue(CrmStr.address1_name);
			}
			set
			{
				AddStringProperty(CrmStr.address1_name,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_telephone1
		{
			get
			{
				return StringPropertyValue(CrmStr.address1_telephone1);
			}
			set
			{
				AddStringProperty(CrmStr.address1_telephone1,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_telephone2
		{
			get
			{
				return StringPropertyValue(CrmStr.address1_telephone2);
			}
			set
			{
				AddStringProperty(CrmStr.address1_telephone2,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_telephone3
		{
			get
			{
				return StringPropertyValue(CrmStr.address1_telephone3);
			}
			set
			{
				AddStringProperty(CrmStr.address1_telephone3,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_fax
		{
			get
			{
				return StringPropertyValue(CrmStr.address1_fax);
			}
			set
			{
				AddStringProperty(CrmStr.address1_fax,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_line1
		{
			get
			{
				return StringPropertyValue(CrmStr.address1_line1);
			}
			set
			{
				AddStringProperty(CrmStr.address1_line1,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_line2
		{
			get
			{
				return StringPropertyValue(CrmStr.address1_line2);
			}
			set
			{
				AddStringProperty(CrmStr.address1_line2,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_line3
		{
			get
			{
				return StringPropertyValue(CrmStr.address1_line3);
			}
			set
			{
				AddStringProperty(CrmStr.address1_line3,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_country
        {
            get
            {
				return StringPropertyValue(CrmStr.address1_country);
            }
            set
            {
				AddStringProperty(CrmStr.address1_country,value);
            }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_county
        {
            get
            {
				return StringPropertyValue(CrmStr.address1_county);
            }
            set
            {
				AddStringProperty(CrmStr.address1_county,value);
            }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_postalcode
        {
            get
            {
				return StringPropertyValue(CrmStr.address1_postalcode);
            }
            set 
             {
				AddStringProperty(CrmStr.address1_postalcode,value);
              }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_city
        {
            get
            {
				return StringPropertyValue(CrmStr.address1_city);
            }
            set 
             {
				AddStringProperty(CrmStr.address1_city,value);
             }
        }
       
        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_stateorprovince
        {
            get
            {
				return StringPropertyValue(CrmStr.address1_stateorprovince);
            }
            set 
             {
				AddStringProperty(CrmStr.address1_stateorprovince,value);
             }
        }
       
        [CrmDynAttribute(CrmStr.businessunit)]
        public string address1_upszone
        {
            get
            {
				return StringPropertyValue(CrmStr.address1_upszone);
            }
            set 
             {
				AddStringProperty(CrmStr.address1_upszone,value);
             }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public double address1_longitude
        {
            get
            {
				return DoublePropertyValue(CrmStr.address1_longitude);
            }
            set 
             {
				AddFloatProperty(CrmStr.address1_longitude,value);
             }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public double address1_latitude
        {
            get
            {
				return DoublePropertyValue(CrmStr.address1_latitude);
            }
            set 
             {
				AddFloatProperty(CrmStr.address1_latitude,value);
             }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public int address1_utcoffset
        {
            get
            {
                if ( ContainsKey(CrmStr.address1_utcoffset) )
                    return NumberPropertyValue(CrmStr.address1_utcoffset);
                return 0;
            }
            set
            {
                AddNumberProperty(CrmStr.address2_utcoffset,value);
            }
        }
        
        #endregion address1
   
        #region address2

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_primarycontactname
		{
			get
			{
				return StringPropertyValue(CrmStr.address2_primarycontactname);
			}
			set
			{
				AddStringProperty(CrmStr.address2_primarycontactname,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public int address2_addresstypecode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.address2_addresstypecode);
			}
			set
			{
				AddPicklistProperty(CrmStr.address2_addresstypecode,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_addresstypecodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.address2_addresstypecode) )
                    return PicklistPropertyLabelValue(CrmStr.address2_addresstypecode);
                return string.Empty;
            }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public int address2_shippingmethodcode
		{
			get
			{
				return PicklistPropertyIntValue(CrmStr.address2_shippingmethodcode);
			}
			set
			{
				AddPicklistProperty(CrmStr.address2_shippingmethodcode,value);
			}
		}

        public string address2_shippingmethodcodeLabel
        {
            get
            {
                if ( ContainsKey(CrmStr.address2_shippingmethodcode) )
                    return PicklistPropertyLabelValue(CrmStr.address2_shippingmethodcode);
                return string.Empty;
            }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_name
		{
			get
			{
				return StringPropertyValue(CrmStr.address2_name);
			}
			set
			{
				AddStringProperty(CrmStr.address2_name,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_telephone1
		{
			get
			{
				return StringPropertyValue(CrmStr.address2_telephone1);
			}
			set
			{
				AddStringProperty(CrmStr.address2_telephone1,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_telephone2
		{
			get
			{
				return StringPropertyValue(CrmStr.address2_telephone2);
			}
			set
			{
				AddStringProperty(CrmStr.address2_telephone2,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_telephone3
		{
			get
			{
				return StringPropertyValue(CrmStr.address2_telephone3);
			}
			set
			{
				AddStringProperty(CrmStr.address2_telephone3,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_fax
		{
			get
			{
				return StringPropertyValue(CrmStr.address2_fax);
			}
			set
			{
				AddStringProperty(CrmStr.address2_fax,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_line1
		{
			get
			{
				return StringPropertyValue(CrmStr.address2_line1);
			}
			set
			{
				AddStringProperty(CrmStr.address2_line1,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_line2
		{
			get
			{
				return StringPropertyValue(CrmStr.address2_line2);
			}
			set
			{
				AddStringProperty(CrmStr.address2_line2,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_line3
		{
			get
			{
				return StringPropertyValue(CrmStr.address2_line3);
			}
			set
			{
				AddStringProperty(CrmStr.address2_line3,value);
			}
		}

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_country
        {
            get
            {
				return StringPropertyValue(CrmStr.address2_country);
            }
            set
            {
				AddStringProperty(CrmStr.address2_country,value);
            }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_county
        {
            get
            {
				return StringPropertyValue(CrmStr.address2_county);
            }
            set
            {
				AddStringProperty(CrmStr.address2_county,value);
            }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_postalcode
        {
            get
            {
				return StringPropertyValue(CrmStr.address2_postalcode);
            }
            set 
             {
				AddStringProperty(CrmStr.address2_postalcode,value);
              }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_city
        {
            get
            {
				return StringPropertyValue(CrmStr.address2_city);
            }
            set 
             {
				AddStringProperty(CrmStr.address2_city,value);
             }
        }
       
        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_stateorprovince
        {
            get
            {
				return StringPropertyValue(CrmStr.address2_stateorprovince);
            }
            set 
             {
				AddStringProperty(CrmStr.address2_stateorprovince,value);
             }
        }
       
        [CrmDynAttribute(CrmStr.businessunit)]
        public string address2_upszone
        {
            get
            {
				return StringPropertyValue(CrmStr.address2_upszone);
            }
            set 
             {
				AddStringProperty(CrmStr.address2_upszone,value);
             }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public double address2_longitude
        {
            get
            {
				return DoublePropertyValue(CrmStr.address2_longitude);
            }
            set 
             {
				AddFloatProperty(CrmStr.address2_longitude,value);
             }
        }

        [CrmDynAttribute(CrmStr.businessunit)]
        public double address2_latitude
        {
            get
            {
				return DoublePropertyValue(CrmStr.address2_latitude);
            }
            set 
             {
				AddFloatProperty(CrmStr.address2_latitude,value);
             }
        }
         
        [CrmDynAttribute(CrmStr.businessunit)]
        public int address2_utcoffset
        {
            get
            {
                if ( ContainsKey(CrmStr.address2_utcoffset) )
                    return NumberPropertyValue(CrmStr.address2_utcoffset);
                return 0;
            }
            set
            {
                AddNumberProperty(CrmStr.address2_utcoffset,value);
            }
        }

        #endregion address2

     }
}
